package com.hxt.util;

import java.util.List;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

import com.google.common.collect.Lists;
import com.hxt.xt.service.z.bean.ProdcutBean;

public class TypeConvert {

	/**
	 * 去掉最后一个逗号
	 * 
	 * @param src
	 * @return
	 */
	public static String getString(String src) {

		return src.substring(0, src.length() - 1);
	}

	public static long intTolong(int src) {
		return Long.parseLong(Integer.valueOf(src).toString());
	}

	public static int longToint(long src) {
		return Integer.parseInt(Long.valueOf(src).toString());
	}

	public static String longToStr(long src) {
		return String.valueOf(src);
	}

	public static int strToint(String src) {
		return Integer.parseInt((Integer.valueOf(src).toString()));
	}

	public static long strTolong(String src) {
		return Long.parseLong((Integer.valueOf(src).toString()));
	}

	public static String intToStr(int src) {
		return String.valueOf(src);
	}

	public static List<Integer> strToListInt(String src) {
		List<Integer> list = Lists.newArrayList();
		if (StringUtils.isNotBlank(src)) {
			String tmp[] = src.split(",");
			for (String t : tmp) {
				list.add(TypeConvert.strToint(t));
			}
		}
		return list;
	}

	public static List<ProdcutBean> strToProductBean(List<String[]> lt) {

		List<ProdcutBean> list = Lists.newArrayList();

		if (BooleanUtils.negate(ObjectUtils.isEmpty(lt))) {
			for (String[] p : lt) {
				ProdcutBean pro = new ProdcutBean(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10],
						p[11], p[12], p[13]);
				list.add(pro);
			}
		}

		return list;
	}

	/**
	 * txId名称转换
	 * 
	 * @param txid
	 * @return
	 */
	public static String convertName(String txid) {
		switch (txid) {
		case "login":
			return "com10001";

		case "getProvince":
			return "com10003";

		case "getCity":
			return "com10004";

		case "getSheetTitle":
			return "com10005";

		case "getProductName":
			return "com10006";

		case "getProductModel":
			return "com10007";

		case "impStorageList":
			return "com10008";

		case "outStorage":
			return "com10009";

		case "importProduct":
			return "com10010";

		case "storageList":
			return "com10011";

		case "storageDetail":
			return "com10012";

		case "getSysTitle":
			return "com10013";

		case "saveXlsTemple":
			return "com10014";

		case "xlsTempleList":
			return "com10015";

		case "delXlsTemple":
			return "com10016";

		case "impStorageListAdmin":
			return "com10017";

		case "impStorageListDetail":
			return "com10018";

		case "getDOutStorageList":
			return "com10019";

		case "inputDealer":
			return "com10020";

		case "queryDealer":
			return "com10021";

		case "delDealer":
			return "com10022";

		case "searchDealer":
			return "com10023";

		case "editDealer":
			return "com10024";

		case "getInvoiceList":
			return "com10025";

		case "makeInvoice":
			return "com10026";

		case "editInvoice":
			return "com10027";

		case "dOutStorage":
			return "com10028";

		case "dOutStorageList":
			return "com10029";

		case "storageListByType":
			return "com10030";

		case "retSign":
			return "com10098";

		case "getUbt":
			return "com10099";

		default:
			return txid;
		}
	}

}